layui.use(['form','layarea'], function () {
    var form = layui.form,
        layer = layui.layer,
        layarea = layui.layarea,
        $ = layui.$;
    layarea.render({
        elem: '#area-picker',

        change: function (res) {
            //选择结果
            // console.log(res);
        }
    });
    //监听提交
    form.on('submit(saveBtn)', function (data) {
        var index = layer.confirm("确认更新？？",function(index){
            console.log("Debug sub mem info:",data.field);
                $.ajax({
                    url:"/Member/update",
                    type:"post",
                    data:JSON.stringify([data.field]),
                    datatype:"json",
                });
                // table.reload('currentTableId');
                layer.close(index);
                var iframeIndex = parent.layer.getFrameIndex(window.name);
                    parent.layer.close(iframeIndex);
            });


        return false;
    });

});

function GetQueryString(name) {
    let reg = new RegExp("(^|&)"+name+"=([^&]*)(&|$)");
    let r = window.location.search.substr(1).match(reg);
    if (r!=null){
        return decodeURI(r[2]);
    }
    return null;
}
var rule_uid = GetQueryString("id");

function init(){
    layui.use(['form','layarea'], function () {
        var form = layui.form,
            layer = layui.layer,
            layarea = layui.layarea,
            $ = layui.$;
        $.ajax({
            url:"/Member/view",
            type:"Get",
            data:"ruleuid=" + rule_uid,
            datatype:"json",
            async:true,
            success:(res)=>{
                // console.log("Debug Mem view:",res);
                form.val("mem-edit", {
                    "mem_uid":res[0].mem_uid
                    ,"username":res[0].username
                    ,"userphone":res[0].userphone
                    // ,"province":res[0].province
                    // ,"city":res[0].city
                    // ,"county":res[0].district
                    ,"detailaddress":res[0].detailaddress
                    ,"remark":res[0].remark
                });
                layarea.render({
                    elem:"#area-picker"
                    ,data:{
                        province:res[0].province,
                        city:res[0].city,
                        county:res[0].district,
                    }
                });
                // layui.form.render("select");
            }
        });
    });
}

